﻿using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Text.RegularExpressions;
//edit
//move/delete
//move/add
//add
//branch
//integrate


namespace ChangeListUtility
{
    class Program
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        private static string getMerger()
        {
            // const string 
            // const string merger = @"C:\Program Files (x86)\Araxis\Araxis Merge v6.5\Merge.exe";
            const string merger = @"C:\Program Files (x86)\Araxis\Araxis Merge v6.5\p4diff.exe";
            string res = "\"" + merger + "\"";
            return res;
        }

        /// <summary>
        /// get only the changed files section and change list desc
        /// </summary>
        /// <param name="describeStr"></param>
        /// <param name="changelistDesc"></param>
        /// <param name="changedFiles"></param>
        /// <returns></returns>
        private static bool processDescribeString(string describeStr, out string changelistDesc, out p4ChangeList changedFiles)
        {
            p4DescHanlder p4DescWorker = new p4DescHanlder(describeStr);

            p4DescWorker.work(out changelistDesc, out changedFiles);

            return true;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="changeListID"></param>
        /// <returns></returns>
        private static bool compareChangeList(string changeListID)
        {
            // describe change list
            p4Wrapper p4 = new p4Wrapper();
            string outputstr;
            p4.executeP4Cmd(p4Wrapper.p4Cmds.p4Cmd_Describe, p4Wrapper.p4Depots.p4Depot_ACA, changeListID, out outputstr);

            string changelistDesc;
            p4ChangeList changedFiles;
            //TODO
            processDescribeString(outputstr, out changelistDesc, out changedFiles);

            Console.WriteLine(changelistDesc);

            p4FileCollection prevRevision = changedFiles.GetprevRevision();

            p4FileCollection curRevision = changedFiles.getNewRevisionFiles();

            string dummy = "";
            foreach (p4File curP4File in prevRevision)
            {
                // new directory
                p4.executeP4Cmd(p4Wrapper.p4Cmds.p4Cmd_PrintFile, p4Wrapper.p4Depots.p4Depot_ACA, "", dummy);
            }

            foreach (p4File curP4File in curRevision)
            {
                // directory
                p4.executeP4Cmd(p4Wrapper.p4Cmds.p4Cmd_PrintFile, p4Wrapper.p4Depots.p4Depot_ACA, "", dummy);
            }
            // create some dir for prev rivision files
            // create some dir for current revision files
            // sync old files to root (some dir) (directory conversion)

            return false;
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            compareChangeList("147353");
            Console.ReadKey();
        }
    }
}
